import Vue from 'vue'
import Router from 'vue-router'


Vue.use(Router)

let router = new Router({
  routes: [
    {
      path: '/',
      name: 'home',
      component: resolve => require(['../page/home.vue'], resolve),
      meta: {
        title: "正在热映"
      },
      children: [
        {
          path: 'detail/:id',
          name: 'detail',
          component: resolve => require(['../components/detail.vue'], resolve),
          meta: {
            title: "电影条目"
          }
        }
      ]
    }
  ]
})

// router.beforeEach((to, from, next) => {
//   if (to.meta.requireAuth) {  // 判断该路由是否需要登录权限
//     if (store.state.token) {  // 通过vuex state获取当前的token是否存在
//       next();
//     }
//     else {
//       next({
//         path: '/login',
//         query: {redirect: to.fullPath}  // 将跳转的路由path作为参数，登录成功后跳转到该路由
//       })
//     }
//   }
//   else {
//     next();
//   }
// })

export default router
